package com.bmadmin.controller.form;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.bmadmin.domain.Datagrid;
import com.bmadmin.domain.LayUiDataTablePOJO;
import com.bmadmin.domain.NormalResult;
import com.bmadmin.domain.SysUsersPOJO;
import com.bmadmin.domain.TysxDomain;
import com.bmadmin.service.TysxService;
import com.bmadmin.util.BMUtil;
import com.bmadmin.util.Constants;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@RestController
@RequestMapping("/tysx")
public class TysxController {
	private Logger logger = LogManager.getLogger(this.getClass().getName());
	
    @Autowired
    TysxService tysxService;
    
    /**
     * 获取事项小类
     */
    @GetMapping("/getMainDbList")
    public LayUiDataTablePOJO getMainDbList(HttpSession session) {
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
    	Map rs = new HashMap();
    	rs.put("depid", user.getD_id());
    	rs.put("userid", user.getU_id());
        LayUiDataTablePOJO result = tysxService.getMainDbList(rs);
        logger.info(result);
        return result;
    }
    
    /**
     * 获取通用事项申请表列表
     */
	@GetMapping("/getTysxApplyList")
    public Object getTysxApplyList(HttpSession session,TysxDomain tysx,Integer page,Integer limit) {
    	Datagrid result = new Datagrid();
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
    	
    	Map map = new HashMap();
		map.put("qs_date", tysx.getQs_date());
		map.put("jz_date", tysx.getJz_date());
		if(tysx.getN_state()==null){
			map.put("n_state", "0,3,4,6");//默认显示表单状态 0--未提交 3--审核未通过 5--接收人退回
		}else if("".equals(tysx.getN_state())){
			map.put("n_state", "0,1,2,3,4,5,6,7");
		}else{
			map.put("n_state", tysx.getN_state());
		}
		map.put("n_apply_userid", user.getU_id());
		
		PageHelper.startPage(page, limit);
		List<TysxDomain> list = tysxService.getTysxApplyList(map);
		PageInfo pagelist = new PageInfo(list);
		
		result.setCode(0);
        result.setMsg("success");
        result.setData(list);
        result.setCount(pagelist.getTotal());

        return result;
    }
	
    /**
     * 获取通用事项审核列表
     */
	@GetMapping("/getTysxVerifyList")
    public Object getTysxVerifyList(HttpSession session,TysxDomain tysx,Integer page,Integer limit) {
    	Datagrid result = new Datagrid();
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
    	
    	Map map = new HashMap();
		map.put("qs_date", tysx.getQs_date());
		map.put("jz_date", tysx.getJz_date());
		if(tysx.getN_state()==null){
			map.put("n_state", "1");//默认显示表单状态 0--未提交 3--审核未通过 5--接收人退回
		}else if("".equals(tysx.getN_state())){
			map.put("n_state", "1,2,3,4,5,6,7");
		}else{
			map.put("n_state", tysx.getN_state());
		}
		map.put("n_apply_depid", user.getD_id());
		
		PageHelper.startPage(page, limit);
		List<TysxDomain> list = tysxService.getTysxApplyList(map);
		PageInfo pagelist = new PageInfo(list);
		
		result.setCode(0);
        result.setMsg("success");
        result.setData(list);
        result.setCount(pagelist.getTotal());

        return result;
    }
	
    /**
     * 获取通用事项审核列表
     */
	@GetMapping("/getTysxDisposeList")
    public Object getTysxDisposeList(HttpSession session,TysxDomain tysx,Integer page,Integer limit) {
    	Datagrid result = new Datagrid();
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
    	
    	Map map = new HashMap();
		map.put("qs_date", tysx.getQs_date());
		map.put("jz_date", tysx.getJz_date());
		if(tysx.getN_state()==null){
			map.put("n_state", "2,5,7");//默认显示表单状态 0--未提交 3--审核未通过 5--接收人退回
		}else if("".equals(tysx.getN_state())){
			map.put("n_state", "2,5,6,7");
		}else{
			map.put("n_state", tysx.getN_state());
		}
		map.put("n_receive_userid", user.getU_id());
		
		PageHelper.startPage(page, limit);
		List<TysxDomain> list = tysxService.getTysxApplyList(map);
		PageInfo pagelist = new PageInfo(list);
		
		result.setCode(0);
        result.setMsg("success");
        result.setData(list);
        result.setCount(pagelist.getTotal());

        return result;
    }
	
    /**
     * 通用事项单审核
     */
    @PostMapping("/verifyTysx")
    public NormalResult verifyTysx(HttpSession session,TysxDomain tysx) {
    	String log = "通用事项单审核>>>>>>>>>>>";
    	logger.info(log+"参数【"+tysx+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(tysx.getN_id())){
        		result.setCode("9999");
                result.setMsg("申请单ID为空！");
                logger.info(log+"申请单ID为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(tysx.getN_verify_view())){
        		result.setCode("9999");
                result.setMsg("发起部门意见为空！");
                logger.info(log+"发起部门意见为空！");
                return result;
        	}
        	
        	tysx.setN_verify_userid(user.getU_id());
        	tysx.setN_verify_date(BMUtil.getNowTimeForString());
        	int retResult = tysxService.verifyTysx(tysx);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("审核成功！");
                logger.info(log+"审核成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("审核失败！");
                logger.info(log+"审核失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("申请单审核异常！");
            logger.error(e);
        }
        return result;
    }
	
    /**
     * 获取事项大类
     */
    @GetMapping("/getSxdlList")
    public LayUiDataTablePOJO getSxdlList() {
        LayUiDataTablePOJO result = tysxService.getSxdlList();
        logger.info(result);
        return result;
    }
    
    /**
     * 获取事项小类
     */
    @GetMapping("/getSxxlList")
    public LayUiDataTablePOJO getSxxlList(String sxdl_dm) {
        LayUiDataTablePOJO result = tysxService.getSxxlList(sxdl_dm);
        logger.info(result);
        return result;
    }
    
    /**
     * 获取事项小类关联人员
     */
    @GetMapping("/getSxxlUserList")
    public LayUiDataTablePOJO getSxxlUserList(String sxxl_dm) {
        LayUiDataTablePOJO result = tysxService.getSxxlUserList(sxxl_dm);
        logger.info(result);
        return result;
    }
    
    /**
     * 获取关联人员部门
     */
    @GetMapping("/getSxxlUserDepname")
    public LayUiDataTablePOJO getSxxlUserDepname(String userid) {
        LayUiDataTablePOJO result = tysxService.getSxxlUserDepname(userid);
        logger.info(result);
        return result;
    }
    
    /**
     * 通用事项保存
     */
    @PostMapping("/insertTysx")
    public NormalResult insertTzs(HttpSession session,TysxDomain tysx) {
    	String log = "通用事项发起保存>>>>>>>>>>>";
    	logger.info(log+"参数【"+tysx+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(tysx.getN_sxdl_dm())){
        		result.setCode("9999");
                result.setMsg("事项大类为空！");
                logger.info(log+"事项大类为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(tysx.getN_sxxl_dm())){
        		result.setCode("9999");
                result.setMsg("事项小类为空！");
                logger.info(log+"事项小类为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(tysx.getN_duetime())){
        		result.setCode("9999");
                result.setMsg("办理期限为空！");
                logger.info(log+"办理期限为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(tysx.getN_apply_phone())){
        		result.setCode("9999");
                result.setMsg("联系电话为空！");
                logger.info(log+"联系电话为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(tysx.getN_receive_userid())){
        		result.setCode("9999");
                result.setMsg("接收人为空！");
                logger.info(log+"接收人为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(tysx.getN_content())){
        		result.setCode("9999");
                result.setMsg("工作事由为空！");
                logger.info(log+"工作事由为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(tysx.getN_demand())){
        		result.setCode("9999");
                result.setMsg("工作要求为空！");
                logger.info(log+"工作要求为空！");
                return result;
        	}

        	tysx.setN_apply_userid(user.getU_id());
        	tysx.setN_apply_depid(user.getD_id());
        	tysx.setN_apply_date(BMUtil.getNowTimeForString());
        	int retResult = tysxService.insertTysx(tysx);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("保存成功！");
                logger.info(log+"保存成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("保存失败！");
                logger.info(log+"保存失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("通用事项保存异常！");
            logger.error(e);
        }
        return result;
    }
    
    /**
     * 通用事项更新
     */
    @PostMapping("/UpdateTysx")
    public NormalResult UpdateTysx(HttpSession session,TysxDomain tysx) {
    	String log = "通用事项更新>>>>>>>>>>>";
    	logger.info(log+"参数【"+tysx+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(tysx.getN_sxdl_dm())){
        		result.setCode("9999");
                result.setMsg("事项大类为空！");
                logger.info(log+"事项大类为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(tysx.getN_sxxl_dm())){
        		result.setCode("9999");
                result.setMsg("事项小类为空！");
                logger.info(log+"事项小类为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(tysx.getN_duetime())){
        		result.setCode("9999");
                result.setMsg("办理期限为空！");
                logger.info(log+"办理期限为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(tysx.getN_apply_phone())){
        		result.setCode("9999");
                result.setMsg("联系电话为空！");
                logger.info(log+"联系电话为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(tysx.getN_receive_userid())){
        		result.setCode("9999");
                result.setMsg("接收人为空！");
                logger.info(log+"接收人为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(tysx.getN_content())){
        		result.setCode("9999");
                result.setMsg("工作事由为空！");
                logger.info(log+"工作事由为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(tysx.getN_demand())){
        		result.setCode("9999");
                result.setMsg("工作要求为空！");
                logger.info(log+"工作要求为空！");
                return result;
        	}

        	tysx.setN_apply_userid(user.getU_id());
        	tysx.setN_apply_depid(user.getD_id());
        	tysx.setN_apply_date(BMUtil.getNowTimeForString());
        	int retResult = tysxService.UpdateTysx(tysx);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("更新成功！");
                logger.info(log+"更新成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("更新失败！");
                logger.info(log+"更新失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("申请单更新异常！");
            logger.error(e);
        }
        return result;
    }
    
    /**
     * 申请单删除
     */
    @PostMapping("/deleteTysx")
    public NormalResult deleteTysx(TysxDomain tysx) {
    	String log = "内部事项发起通知书删除>>>>>>>>>>>";
        NormalResult result = new NormalResult();
        if (BMUtil.isNullOrEmpty(tysx.getN_id())) {
            result.setCode("9999");
            result.setMsg("传入申请单ID为空!");
            return result;
        }

        int retResult = tysxService.deleteTysx(tysx.getN_id());
        if(retResult>0){
    		result.setCode("0000");
            result.setMsg("删除成功！");
            logger.info(log+"删除成功！");
    	}else{
    		result.setCode("9999");
            result.setMsg("删除失败！");
            logger.info(log+"删除失败！");
    	}
    	return result;
    }
    
    /**
     * 申请单验证
     */
    @PostMapping("/sureTysx")
    public NormalResult sureTysx(HttpSession session,TysxDomain tysx) {
    	String log = "通用事项申请单确认>>>>>>>>>>>";
    	logger.info(log+"参数【"+tysx+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(tysx.getN_id())){
        		result.setCode("9999");
                result.setMsg("申请单ID为空！");
                logger.info(log+"申请单ID为空！");
                return result;
        	}
        	int retResult = tysxService.sureTysx(tysx);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("确认完成！");
                logger.info(log+"确认完成！");
        	}else{
        		result.setCode("9999");
                result.setMsg("确认失败！");
                logger.info(log+"确认失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("申请单确认异常！");
            logger.error(e);
        }
        return result;
    }
    
    /**
     * 申请单接收
     */
    @PostMapping("/receiveTysx")
    public NormalResult receiveTysx(HttpSession session,TysxDomain tysx) {
    	String log = "通用事项申请单接收>>>>>>>>>>>";
    	logger.info(log+"参数【"+tysx+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(tysx.getN_id())){
        		result.setCode("9999");
                result.setMsg("申请单ID为空！");
                logger.info(log+"申请单ID为空！");
                return result;
        	}
        	tysx.setN_receive_date(BMUtil.getNowTimeForString());
        	int retResult = tysxService.receiveTysx(tysx);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("接收成功！");
                logger.info(log+"接收成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("接收失败！");
                logger.info(log+"接收失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("申请单接收异常！");
            logger.error(e);
        }
        return result;
    }
    
    /**
     * 申请单退回
     */
    @PostMapping("/backTysx")
    public NormalResult backTysx(HttpSession session,TysxDomain tysx) {
    	String log = "通用事项申请单接收>>>>>>>>>>>";
    	logger.info(log+"参数【"+tysx+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(tysx.getN_id())){
        		result.setCode("9999");
                result.setMsg("申请单ID为空！");
                logger.info(log+"申请单ID为空！");
                return result;
        	}
        	tysx.setN_receive_date(BMUtil.getNowTimeForString());
        	int retResult = tysxService.receiveTysx(tysx);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("退回成功！");
                logger.info(log+"退回成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("退回失败！");
                logger.info(log+"退回失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("申请单接收异常！");
            logger.error(e);
        }
        return result;
    }
    
    /**
     * 获取通用事项信息
     */
    @GetMapping("/getOneTysx")
    public NormalResult getOneTysx(HttpSession session,String n_id){
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
    	NormalResult result = new NormalResult();
    	if (BMUtil.isNullOrEmpty(n_id)) {
            result.setCode("9999");
            result.setMsg("传入申请单ID为空!");
            return result;
        }
    	Map map = new HashMap();
//    	map.put("userid", user.getU_id());
    	map.put("n_id",Integer.parseInt(n_id));
    	List<TysxDomain> list = tysxService.getTysxApplyList(map);
    	TysxDomain tysxDomain = list.get(0);
       
        result.setCode("0000");
        result.setMsg("success");
        result.setData(tysxDomain);
        return result;
    }
    
    /**
     * 上传通用事项申请单附件
     */
    @PostMapping(value = "uploadfile")
    public NormalResult uploadfile(HttpSession session,MultipartFile file,String n_id)throws IOException {
        SysUsersPOJO user = (SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        InputStream is = null;
        try {
            // 判断文件是否为空
            if (file == null) {
                result.setCode("9999");
                result.setMsg("文件不能为空！");
                return result;
            }

            // 获取文件名
            String fileName = file.getOriginalFilename();
            
            if (!BMUtil.validateExcel(fileName)&&!fileName.contains(".doc")&&!fileName.contains(".pdf")) {
                result.setCode("9999");
                result.setMsg("文件必须是excel或word文件或pdf文件！");
                return result;
            }

            String pdf_location = "D:\\soft\\nginx\\html\\hzwgs\\uploadtysx\\"+n_id+"";
            logger.info("上传文件保存路径：" + pdf_location);
	        File filePath = new File(pdf_location);
	        if (! filePath.exists()) {
	            filePath.mkdirs();
	            logger.info("文件保存路径不存在，创建成功！");
	        }
	        BMUtil.getFile(file.getBytes(), pdf_location, fileName);
	        TysxDomain tysx = new TysxDomain();
	        tysx.setN_id(n_id);
	        tysx.setN_filename(fileName);
	        int res = tysxService.UpdateFileName(tysx);
	        if(res>0){
	        	result.setCode("0000");
	            result.setMsg("上传成功");
	        }else{
	        	result.setCode("9999");
	            result.setMsg("上传失败");
	        }
            return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("文件上传异常！");
            logger.error(e);
            return result;
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    is = null;
                    e.printStackTrace();
                }
            }
        }
    }
    
    /**
     * 申请单附件删除
     */
    @PostMapping("/deleteFile")
    public NormalResult deleteFile(HttpSession session,String n_id) {
    	String log = "删除附件>>>>>>>>>>>";
    	logger.info(log+"参数n_id【"+n_id+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(n_id)){
        		result.setCode("9999");
                result.setMsg("申请单ID为空！");
                logger.info(log+"申请单ID为空！");
                return result;
        	}
        	int retResult = tysxService.deleteFile(n_id);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("附件删除成功！");
                logger.info(log+"附件删除成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("附件删除失败！");
                logger.info(log+"附件删除失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("附件删除异常！");
            logger.error(e);
        }
        return result;
    }
    
    /**
     * 通用事项提交
     */
    @PostMapping("/upTysx")
    public NormalResult upTysx(TysxDomain tysx) {
    	NormalResult result = new NormalResult();
    	try {
	        if (BMUtil.isNullOrEmpty(tysx.getN_id())) {
	            result.setCode("9999");
	            result.setMsg("传入申请单ID为空!");
	            return result;
	        }
	        tysx.setN_state(tysx.getN_state());
	        int retResult = 0;
	        if("2".equals(tysx.getN_state())){
	        	tysx.setN_verify_date(BMUtil.getNowTimeForString());
	        	tysx.setN_verify_userid("admin");
	        	tysx.setN_verify_view("系统自动审批通过");
	        	retResult = tysxService.verifyTysx(tysx);
	        }else{
		        retResult = tysxService.upTysx(tysx);
	        }
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("提交成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("提交失败！");
        	}
        	return result;
    	}catch (Exception e) {
            result.setCode("9999");
            result.setMsg("通用事项申请单提交异常！");
            logger.error(e);
            return result;
        }        
    }
    
    
    @PostMapping(value = "uploadbackfile")
    public NormalResult uploadbackfile(HttpSession session,MultipartFile file,String n_id)throws IOException {
        SysUsersPOJO user = (SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        InputStream is = null;
        try {
            // 判断文件是否为空
            if (file == null) {
                result.setCode("9999");
                result.setMsg("文件不能为空！");
                return result;
            }

            // 获取文件名
            String fileName = file.getOriginalFilename();
            
            if (!BMUtil.validateExcel(fileName)&&!fileName.contains(".doc")&&!fileName.contains(".pdf")) {
                result.setCode("9999");
                result.setMsg("文件必须是excel或word文件或pdf文件！");
                return result;
            }

            String pdf_location = "D:\\soft\\nginx\\html\\hzwgs\\uploadtysxback\\"+n_id+"";
            logger.info("上传文件保存路径：" + pdf_location);
	        File filePath = new File(pdf_location);
	        if (! filePath.exists()) {
	            filePath.mkdirs();
	            logger.info("文件保存路径不存在，创建成功！");
	        }
	        BMUtil.getFile(file.getBytes(), pdf_location, fileName);
	        TysxDomain tysx = new TysxDomain();
	        tysx.setN_id(n_id);
	        tysx.setN_back_filename(fileName);
	        int res = tysxService.UpdateBackFileName(tysx);
	        if(res>0){
	        	result.setCode("0000");
	            result.setMsg("上传成功");
	            Map rs = new HashMap();
	            rs.put("filename", fileName);
	            result.setData(rs);
	        }else{
	        	result.setCode("9999");
	            result.setMsg("上传失败");
	        }
            return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("文件上传异常！");
            logger.error(e);
            return result;
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    is = null;
                    e.printStackTrace();
                }
            }
        }
    }
    
    /**
     * 反馈附件删除
     */
    @PostMapping("/deleteBackFile")
    public NormalResult deleteBackFile(HttpSession session,String n_id) {
    	String log = "删除通用事项处理附件>>>>>>>>>>>";
    	logger.info(log+"参数n_id【"+n_id+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(n_id)){
        		result.setCode("9999");
                result.setMsg("申请单ID为空！");
                logger.info(log+"申请单ID为空！");
                return result;
        	}
        	int retResult = tysxService.deleteBackFile(n_id);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("附件删除成功！");
                logger.info(log+"附件删除成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("附件删除失败！");
                logger.info(log+"附件删除失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("附件删除异常！");
            logger.error(e);
        }
        return result;
    }
    
    /**
     * 申请单处理
     */
    @PostMapping("/disposeTysx")
    public NormalResult disposeTysx(HttpSession session,TysxDomain tysx) {
    	String log = "通用事项申请单处理>>>>>>>>>>>";
    	logger.info(log+"参数【"+tysx+"】");
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(tysx.getN_id())){
        		result.setCode("9999");
                result.setMsg("申请单ID为空！");
                logger.info(log+"申请单ID为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(tysx.getN_back_result())){
        		result.setCode("9999");
                result.setMsg("处理结果为空！");
                logger.info(log+"处理结果为空！");
                return result;
        	}
        	tysx.setN_back_date(BMUtil.getNowTimeForString());
        	int retResult = tysxService.disposeTysx(tysx);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("处理成功！");
                logger.info(log+"处理成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("处理失败！");
                logger.info(log+"处理失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("申请单处理异常！");
            logger.error(e);
        }
        return result;
    }
}
